
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using TreeView.Graphic;


namespace TreeView.Logic
{
    public class RadialTreeNode
    {
       
        private int key;
        private int depth;
        private int hight;

        int clusetNum;
        private double teta;
        private double radius;
        private string genomeName;
        private RadialTreeNode leftSon;
        private RadialTreeNode rightSon;
        private ArrayList sonsCodeNames;
        RadNodeGUI nodeGUI;
        
        #region Constructors


        public RadialTreeNode(double newTeta, int newKey, int newDepth, int newHight, int newNodeSize, int cluster, Color lineColor)
        {
            sonsCodeNames = new ArrayList();
            teta = newTeta;
            depth = newDepth;
            key = newKey;
            hight = newHight;
            radius = (double)newDepth / (double)(newDepth + newHight);
            clusetNum = cluster;
        }

        public RadialTreeNode(double newTeta, int newKey, int newDepth, int newHight,string newName,int cluster,int newNodeSize)
        {
            sonsCodeNames = new ArrayList();
            sonsCodeNames.Add(newKey);
            teta = newTeta;
            depth = newDepth;
            key = newKey;
            hight = newHight;
            radius = (double)newDepth / (double)(newDepth + newHight);
            genomeName = newName;
            clusetNum = cluster;
        }

        #endregion

        #region Properties

        public RadNodeGUI NodeGUI
        {
            set { nodeGUI = value; }
            get { return nodeGUI; }
        }
        public string GenomeName
        {
            get { return genomeName; }
        }

        public ArrayList SonsCodeNames
        {
            get { return sonsCodeNames; }
        }

        public RadialTreeNode LeftSon
        {
            set { leftSon = value; }
            get { return leftSon; }
        }

        public RadialTreeNode RightSon
        {
            set { rightSon = value; }
            get { return rightSon; }
        }

        public Double Teta
        {
            set { teta = value; }
            get { return teta; }
        }

        public int ClusterNum
        {
            set { clusetNum = value; }
            get { return clusetNum; }
        }

        public Double X
        {
            get 
            {   if ((depth!=0)||(hight!=0))
                    return ((double)depth / (double)(depth + hight)) * Math.Cos(teta);
                return 0;
            }
        }

        public Double Y
        {
            get 
            {
                if ((depth != 0) || (hight != 0))
                    return ((double)depth / (double)(depth + hight)) * Math.Sin(teta);
                return 0;
            }
        }

        public int Depth
        {
            set
            {
                depth = value;
                radius = (double)depth / (double)(depth + hight);
            }
            get { return depth; }
        }

        public int Hight
        {
            set { hight = value; }
            get { return hight; }
        }

        public int Key
        {
           get { return key; }
        }

        public Double Radius
        {
            get { return (double)depth / (double)(depth + hight); }
        }

        public String Name
        {
            get { return genomeName; }
        }

       

        #endregion
        
        #region Methods

        public bool isLeaf()
        {
            if ((leftSon == null) && (rightSon == null))
                return true;
            return false;
        }

        public override string ToString()
        {
            if ((leftSon != null) && (rightSon != null))
                return '(' + leftSon.ToString() + ", " + rightSon.ToString() + ')';
            else
                return genomeName;
        }

        #endregion
    }
}
